<?php
class ControllerPost_like { 

    function getFunction($op){
        
        switch ($op) {
            case "new":
                $this->newPostlike();
                break;
            
            case "list":
                $this->listPostlike();
                break;
            
            case "save":
                $this->savePostlike();
                break;

            case "edit":
                $this->editPostlike();
                break;
            
            case "update":
                $this->updatePostlike();
                break;
            
            case "del":
                $this->deletePostlike();
                break;
            
            case "combo":
                return $this->comboPostlike();
                break;
            
            default:
                echo "ERROR NO HAY CONTROLADOR PARA ESA OPCION";
                break;
        }
    }
    

    function newPostlike(){
        include_once "vista/vista.post_like.php";
        form_post_like();
    }    
    

    function savePostlike(){
        include_once "modelo/modelo.post_like.php";
        
        $p = new post_like();
        $p->set_pl_id($_REQUEST["pl_id"]); 
        $p->set_pl_p_id($_REQUEST["pl_p_id"]); 
        $p->set_pl_u_id($_REQUEST["pl_u_id"]); 
        $p->set_pl_date($_REQUEST["pl_date"]); 

        
        if($p->Save()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_save_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_save_error']." </div>";
        }
        $this->listPostlike($msj);
        
    }    
    
    function editPostlike(){
        include_once 'modelo/modelo.post_like.php';
        include_once 'vista/vista.post_like.php';
        
        $p = new post_like();
        $p->setpl_id($_REQUEST["pl_id"]); 
        
        $p->getData();
        
        form_post_like($p);
        
    }    
    
    function deletePostlike(){
        include_once 'modelo/modelo.post_like.php';
        
        $p = new post_like();
        $p->setpl_id($_REQUEST["pl_id"]); 
        
        if($p->Delete()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_delete_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_delete_error']." </div>";
        }
        $this->listPostlike($msj);
    }

    
    function updatePostlike(){
        include_once 'modelo/modelo.post_like.php';
        
        $p = new post_like();
        $p->set_pl_id($_REQUEST["pl_id"]); 
        $p->set_pl_p_id($_REQUEST["pl_p_id"]); 
        $p->set_pl_u_id($_REQUEST["pl_u_id"]); 
        $p->set_pl_date($_REQUEST["pl_date"]); 

        if($p->Update()){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_ok']." '> <img src='".$_SESSION['alert']['image_ok']."' /> ".$_SESSION['alert']['msj_update_ok']." </div>";
        }else{
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_update_error']." </div>";
        }
        $this->listPostlike($msj);
    }

    
    function listPostlike($msj=false){
        include_once 'modelo/modelo.post_like.php';
        include_once 'vista/vista.post_like.php';
        
        $p = new post_like();

        $p->setpl_id($_REQUEST["pl_id"]); 
        $p->getData();
        
        $dataTotal = $p->GetList(" count(*) ", false,  true);
        $dataTotal = $dataTotal[0][0]; 
        $data = $p->GetList(" * ", false);
        if(is_null($data)){
            $msj = "<div id='alertzone' style='".$_SESSION['alert']['style_error']."'> <img src='".$_SESSION['alert']['image_error']."' /> ".$_SESSION['alert']['msj_empty_error']." </div>";
        }
        list_post_like($data, $msj, $dataTotal);

    }

}